package com.zzyl.nursing.controller;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.NursingTask;
import com.zzyl.nursing.dto.CancelTaskDto;
import com.zzyl.nursing.dto.DoTaskDto;
import com.zzyl.nursing.dto.RescheduleTaskDto;
import com.zzyl.nursing.service.INursingTaskService;
import com.zzyl.nursing.vo.NursingTaskDetailVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 护理任务Controller
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/nursing/nursingTask")
public class NursingTaskController extends BaseController
{
    @Autowired
    private INursingTaskService nursingTaskService;
    /**
     * 查询护理任务列表
     */
    @GetMapping("/list")
    public TableDataInfo list(NursingTask nursingTask) {
        startPage();
        List<NursingTask> list = nursingTaskService.selectNursingTaskList(nursingTask);
        return getDataTable(list);
    }

    /**
     * 获取护理任务详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getNursingTaskById(@PathVariable("id") Long id) {
        NursingTaskDetailVo nursingTaskDetail = nursingTaskService.getNursingTaskDetailById(id);
        return AjaxResult.success(nursingTaskDetail);
    }


    /**
     * 取消任务
     */
    @PutMapping("/cancel")
    public AjaxResult cancelNursingTask(@RequestBody CancelTaskDto dto) {
        nursingTaskService.cancelNursingTask(dto.getTaskId(), dto.getReason());
        return success();
    }

    /**
     * 任务执行
     */
    @PutMapping("/do")
    public AjaxResult doTask(@RequestBody DoTaskDto dto) {
        nursingTaskService.doTask(dto);
        return AjaxResult.success("操作成功");
    }

    /**
     * 任务改期
     */
    @PutMapping("/updateTime")
    public AjaxResult rescheduleNursingTask(@RequestBody RescheduleTaskDto dto) {
        try {
            nursingTaskService.rescheduleNursingTask(dto);
            return AjaxResult.success("操作成功");
        } catch (Exception e) {
            return AjaxResult.error("任务改期失败: " + e.getMessage());
        }
    }


}
